package com.promfy.userinterface.views.customizeprocessbar;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MyProcessBar extends LinearLayout {
	
	private Context context;
	private AttributeSet attrs;
	private int stepNum;
	private Integer resId;
	
	public MyProcessBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		this.attrs = attrs;
		
	}

	/**
	 * init state of steps.
	 * @param stepNum -- totally steps.
	 * @param resId -- resource of step when it dosen't work.
	 */
	public void initView(int stepNum, Integer resId){
		this.stepNum = stepNum;
		this.resId = resId;
		for(int i=0; i<stepNum; i++){
			ImageView imageView = new ImageView(context, attrs);
			if(resId != null)
				imageView.setImageResource(resId);
			addView(imageView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,1));
		}   
	}
	
	/**
	 * on state of steps.
	 * @param step -- step numbers which have worked.
	 * @param changedResId -- resource of step which it have worked.
	 */
	public void onStep(int step, Integer changedResId){
		removeAllViews();
		for(int i=0; i<step && i < stepNum; i++){
			ImageView imageView = new ImageView(context, attrs);
			if(changedResId != null)
				imageView.setImageResource(changedResId);
			addView(imageView, i, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,1));
		}
		for(int i= step; i< stepNum; i++){
			ImageView imageView = new ImageView(context, attrs);
			if(resId != null)
				imageView.setImageResource(resId);
			addView(imageView, i, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,1));
		}
	} 

}